package avicit.bdp.dcs.json.service.reader;

import avicit.bdp.dcs.datasource.dto.JobDatasource;
import avicit.bdp.dcs.plugin.BaseDataxParam;
import avicit.bdp.dcs.semistructure.dto.FileTemplateDTO;
import avicit.bdp.dcs.task.dto.TaskDTO;
import avicit.bdp.dcs.utils.JdbcConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class FileReaderBuilder {

  @Autowired private OssReaderBuilder ossReaderBuilder;
  @Autowired private HdfsReaderBuilder hdfsReaderBuilder;

  /** 构建文件采集Reader */
  public BaseDataxParam buildReaderByFile(
      TaskDTO taskDTO,
      JobDatasource readerDatasource,
      FileTemplateDTO fileTemplate)
      throws Exception {
    if (JdbcConstants.OSS.equals(readerDatasource.getDbType())) {
      return ossReaderBuilder.buildOssReaderByFile(taskDTO, readerDatasource, fileTemplate);
    } else {
      return hdfsReaderBuilder.buildHdfsReaderByFile(taskDTO, readerDatasource, fileTemplate);
    }
  }
}
